//
//  RTUserAcount.swift
//  Weibo
//
//  Created by Brisinga on 16/3/5.
//  Copyright © 2016年 Root. All rights reserved.
//

import UIKit

class RTUserAcount: NSObject,NSCoding {
    
    // 访问盾牌
    var access_token: String?
    
    // access_token的生命周期，单位是秒数
    var expires_in: Double = 0 {
        
        didSet {
            
            expires_Date = NSDate().dateByAddingTimeInterval(expires_in)
        }
    }
    
    // 授权过期时间
    var expires_Date: NSDate?
    
    // 当前授权用户的UID
    var uid: String?
    
    // access_token的生命周期（该参数即将废弃，开发者请使用expires_in）
    var remind_in: String?
    
    // 用户名
    var screen_name: String?
    
    // 小图片
    var profile_image_url: String?
    
    // 大图片
    var avatar_large: String?
    
    init(dict: [String: AnyObject]) {
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
    // 重写description
    override var description: String {
        
        let keys = ["access_token","expires_in","uid"]
        
        return dictionaryWithValuesForKeys(keys).description
    }
    
    
    
    // 归档
    func encodeWithCoder(aCoder: NSCoder) {
        
        aCoder.encodeObject(access_token, forKey: "access_token")
        aCoder.encodeDouble(expires_in, forKey: "expires_in")
        aCoder.encodeObject(uid, forKey: "uid")
        aCoder.encodeObject(remind_in, forKey: "remind_in")
        aCoder.encodeObject(screen_name, forKey: "screen_name")
        aCoder.encodeObject(profile_image_url, forKey: "profile_image_url")
        aCoder.encodeObject(avatar_large, forKey: "avatar_large")
        aCoder.encodeObject(expires_Date, forKey: "expires_Date")
        
    }
    
    
    // 解档
    required init?(coder aDecoder: NSCoder) {
        
        access_token = aDecoder.decodeObjectForKey("access_token") as? String
        expires_in = aDecoder.decodeDoubleForKey("expires_in")
        uid = aDecoder.decodeObjectForKey("uid") as? String
        remind_in = aDecoder.decodeObjectForKey("remind_in") as? String
        screen_name = aDecoder.decodeObjectForKey("screen_name") as? String
        profile_image_url = aDecoder.decodeObjectForKey("profile_image_url") as? String
        
        avatar_large = aDecoder.decodeObjectForKey("avatar_large") as? String
        expires_Date = aDecoder.decodeObjectForKey("expires_Date") as? NSDate
        
    }
    
}
